package com.flame.application.service;

import com.flame.ai.pdf.PdfDocumentReader;
import com.flame.application.entity.bean.Book;
import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Jflame
 * @version 1.0.0
 * @since 2025/8/17
 */
@Service
public class RagService {

    private static final String METADATA_ID = "id";

    @Resource
    private PdfDocumentReader pdfDocumentReader;

    @Resource
    private VectorStore vectorStore;

    public void embedToVectorStore(Book book) {
        List<Document> documents = pdfDocumentReader.get(book.getPath());
        documents.stream().forEach(document -> {
            document.getMetadata().put(METADATA_ID, book.getBookId());
        });
        vectorStore.add(documents);
    }
}
